package com.sczmgk.syevaluation.utils;

import com.sczmgk.syevaluation.entity.base.BaseEntity;
import com.sczmgk.syevaluation.entity.input.LoginInput;
import com.sczmgk.syevaluation.entity.output.AppVersion;
import com.sczmgk.syevaluation.entity.output.LoginStatus;
import com.sczmgk.syevaluation.entity.output.UserMetter;

import java.io.IOException;

import okhttp3.MediaType;
import okhttp3.ResponseBody;
import okio.Buffer;
import okio.BufferedSource;
import okio.ForwardingSource;
import okio.Okio;
import okio.Source;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Streaming;
import retrofit2.http.Url;

public class HttpTools {

    private static HttpInterf mApi;

    public static HttpInterf getService() {
        if (mApi == null) {
            Retrofit retrofit = new Retrofit.Builder()
                    //使用自定义的mGsonConverterFactory
                    .addConverterFactory(GsonConverterFactory.create())
                    //设置网络请求的Url地址
                    .baseUrl("http://112.25.171.120:8064/api/appApi/")
    //                .baseUrl("http://192.168.0.181:8066/api/appApi/")
                    .build();
            // 创建网络请求接口的实例
            mApi = retrofit.create(HttpInterf.class);
        }
        return mApi;
    }

    public interface HttpInterf {

        /**
         * 获取登录状态
         * @param loginInput
         * @return     Call<ResponseBody> 返回json原字符串
         */
        @Headers({"Content-Type: application/json", "Accept:  application/json"})
        @POST("user/getloginstatus")
        Call<LoginStatus> getLoginStatus(@Body LoginInput loginInput);

        /**
         * 登录
         * @param loginInput
         * @return     Call<ResponseBody> 返回json原字符串
         */
        @Headers({"Content-Type: application/json", "Accept:  application/json"})
        @POST("user/login")
        Call<UserMetter> login(@Body LoginInput loginInput);


        /**
         * 提交评价
         * @param loginInput
         * @return
         */
        @Headers({"Content-Type: application/json", "Accept:  application/json"})
        @POST("evaluation/add")
        Call<BaseEntity<Object>> commit(@Body LoginInput loginInput);

        /**
         * 获取app版本信息
         * @return
         */
        @Headers({"Content-Type: application/json", "Accept:  application/json"})
        @POST("config/getversion")
        Call<AppVersion> getVersion();

        /**
         * 下载文件
         * @param fileUrl
         * @return
         */
        @Streaming
        @GET
        Call<ResponseBody> downloadFile(@Url String fileUrl);

        /**
         * 更新窗口数据
         * @param loginInput
         * @return     Call<ResponseBody> 返回json原字符串
         */
        @Headers({"Content-Type: application/json", "Accept:  application/json"})
        @POST("user/getinfo")
        Call<UserMetter> updataWindowInfo(@Body LoginInput loginInput);


        /**
         * 发送评价指令
         * @param loginInput
         * @return     Call<ResponseBody> 返回json原字符串
         */
        @Headers({"Content-Type: application/json", "Accept:  application/json"})
        @POST("command/send")
        Call<BaseEntity<Object>> sendCommand(@Body LoginInput loginInput);

        /**
         * 获取评价指令
         * @param loginInput
         * @return     Call<ResponseBody> 返回json原字符串
         */
        @Headers({"Content-Type: application/json", "Accept:  application/json"})
        @POST("command/getcommand")
        Call<LoginStatus> getCommand(@Body LoginInput loginInput);

        /**
         * 获取评价指令
         * @param loginInput
         * @return     Call<ResponseBody> 返回json原字符串
         */
        @Headers({"Content-Type: application/json", "Accept:  application/json"})
        @POST("command/clear")
        Call<BaseEntity<Object>> clearCommand(@Body LoginInput loginInput);


    }

}
